PackageDescription: Transducers Classic API


Transducers Classic API

Last published: April 11, 2023 by 'stm'

Defines 0 Classes
Extends 5 Classes


Transducers Classic API provides methods to process collections, streams and reducibles in a classic collection API style.


# Overview

## Reducible provides two new methods
- #into: collects all elements in a data drain (collection, stream) that understands #accumulate.
- #transduce wraps the reducible into an eduction to provide access to exended protocol.

## Classic collection API style
Eduction is extended by methods that apply specific transducers to the receiver, e.g.,
- #map: applies a Map transducer to the receiver which maps all elements similar to #collect:
- #filter: applies a Filter transducer to the reciever which filters all elements similar to #select:
We use other seletors than collections to make the differences explicit, e.g., no intermediate collections.


# Usage by Example

1. We follow the example from the transducers package which
builds a coin flipping experiment and counts the occurrence of heads and tails.

| scale label coin samples result |
scale := [:x | (x * 2 + 1) floor].
label := #(heads tails).

"We use #map:, #replace:, #take: and #into: to set up and execute the experiment"

coin := (Random new transduce map: scale) replace: label.
samples := coin take: 1000.
result := samples into: Bag new.


2. We build two sets containing negated respectively squared odd number from 1 to: 10.

| odds negatedOdds squaredOdds |
odds := (1 to: 10) transduce filter: #odd.
negatedOdds := (odds map: #negated) into: Set.
squaredOdds := (odds map: #squared) into: Set.